package com.skywolf.chem.usercenterapi.service.impl;

import com.skywolf.chem.common.sysconfig.pojo.vo.PageVO;
import com.skywolf.chem.manager.entity.OpinionParam;
import com.skywolf.chem.usercenterapi.entity.SuggestInfo;
import com.skywolf.chem.usercenterapi.mapper.SuggestInfoMapper;
import com.skywolf.chem.usercenterapi.service.ISuggestInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 系统建议信息采集表 服务实现类
 * </p>
 *
 * @author 
 * @since 2020-06-09
 */
@Service
public class SuggestInfoServiceImpl extends ServiceImpl<SuggestInfoMapper, SuggestInfo> implements ISuggestInfoService {

    @Autowired
    SuggestInfoMapper suggestInfoMapper;

    @Override
    public PageVO<SuggestInfo> pageSuggestInfoList(OpinionParam queryParam) {
        Long startNum = queryParam.getPageSize()*(queryParam.getPageNum()-1);
        Long endNum = queryParam.getPageSize();
        Integer count = suggestInfoMapper.getSuggestPageCount(queryParam.getUid(),queryParam.getStatus(),queryParam.getSugDesc());
        List<SuggestInfo> list = suggestInfoMapper.getSuggestPageList(queryParam.getUid(),startNum,endNum,
                queryParam.getStatus(),queryParam.getSugDesc());

        PageVO<SuggestInfo> pageVO = new PageVO<>();
        pageVO.setList(list);
        pageVO.setTotal(Long.valueOf(count));
        pageVO.setPageSize(queryParam.getPageSize());
        pageVO.setPageNum(queryParam.getPageNum());
        Long totalPage = (count/queryParam.getPageSize())+(count%queryParam.getPageSize()>0?1:0);
        if(totalPage.equals(0)){
            totalPage = queryParam.getPageNum();
        }
        pageVO.setPages(totalPage);
        return pageVO;
    }
}
